
Component({
  /**
   * 组件的一些选项
   */
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的对外属性
   */
  properties: {
    autofocus: {
      type: Boolean,
      default: false
    },
    adapterSource: {
      type: Array,
      default: []
    },
    title: {
      type: String,
      default: ''
    },
    value: {
      type: String,
      default: ''
    },
    placeholder: {
      type: String,
      default: '请输入内容'
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    bindSource: [],
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //当键盘输入时，触发input事件
    bindinput: function (e) {
      var prefix = e.detail.value//用户实时输入值
      var newSource = []//匹配的结果
      if (prefix != '') {
        this.data.adapterSource.forEach(function (e) {
          if ((e.type != undefined && e.type.indexOf(prefix) >= 0)
            || (e.type == undefined && e.indexOf(prefix) >= 0)) {
            newSource.push(e.type != undefined ? e.type : e)
          }
        })
      }
      this.setData({
        bindSource: newSource
      })
      this.triggerEvent('change', { value: prefix });
    },
    bindfocus(e) {
      //console.log('bindfocus')
      this.triggerEvent('focus', { e });
    },
    bindblur(e) {
      setTimeout(() => {
        //console.log('bindblur')
        this.setData({
          bindSource: []
        })
      }, 200)
    },
    itemtap: function (e) {
      //console.log('itemtap', e)
      let src = e.currentTarget.dataset.src;
      this.setData({
        value: src,
        bindSource: []
      })

      this.triggerEvent('change', { value: src });
    }
  }
})